package com.jf.service.impl;

import com.jf.bean.School;
import com.jf.dao.SchoolDao;
import com.jf.dao.impl.SchoolDaoImpl;
import com.jf.service.SchoolService;
import com.jf.util.PageInfo;
import com.jf.util.ResultJson;

import java.util.List;

public class SchoolServiceImpl implements SchoolService {
    private SchoolDao schoolDao = new SchoolDaoImpl();
    @Override
    public ResultJson getPage(PageInfo pageInfo, School school) {
        List<School> list = schoolDao.getPage(pageInfo, school);
        int count = schoolDao.getCount(school);
        pageInfo.setPageData(list,count);
        return ResultJson.success(pageInfo);
    }

    @Override
    public ResultJson saveOrUpdate(School school) {
        int result;
        if(school.getId() == null){
            result = schoolDao.addSelect(school);
        }else{
            result = schoolDao.updateSelect(school);
        }
        return result > 0 ?ResultJson.success():ResultJson.error("操作失败");
    }

    @Override
    public ResultJson delete(int[] ids) {
        int result = schoolDao.batchDelete(ids);
        return result == ids.length ? ResultJson.success():ResultJson.error("删除异常！");
    }

    @Override
    public ResultJson info(int id) {
        return ResultJson.success(schoolDao.getById(id));
    }

    @Override
    public ResultJson getList() {
        return ResultJson.success(schoolDao.getList());
    }
}
